package top.ezzz.search.model;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.Arrays;

/**
 * ElasticSearch 字段控制
 *
 * @author noear
 * @since 1.0
 */
public class EsSource {

    private final JSONObject oNode;

    public EsSource(JSONObject oNode) {
        this.oNode = oNode;
    }

    public EsSource includes(String... includes) {
        if (oNode.get("includes") == null) {
            oNode.set("includes", JSONUtil.createArray());
        }
        oNode.getJSONArray("includes").addAll(Arrays.asList(includes));
        return this;
    }

    public EsSource excludes(String... includes) {
        if (oNode.get("excludes") == null) {
            oNode.set("excludes", JSONUtil.createArray());
        }
        oNode.getJSONArray("excludes").addAll(Arrays.asList(includes));
        return this;
    }
}
